package com.demo.danmu;

import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

import com.demo.danmu.model.Barrage;
import com.demo.danmu.view.BarrageView;

import java.util.ArrayList;

public class MainActivity1 extends AppCompatActivity{
    BarrageView barrageview;
    ArrayList<Barrage> data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main1);
        initView();

        //收到A传过来的消息
        if(getIntent() != null){
            String msg = getIntent().getStringExtra("message");
            if(!TextUtils.isEmpty(msg)){
                new AlertDialog.Builder(MainActivity1.this).setMessage(msg).setTitle("收到消息")
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                            }
                        }).show();
            }
        }

        final EditText et_senddanmu = (EditText) findViewById(R.id.et_senddanmu);
        findViewById(R.id.btn_send).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                barrageview.sendNewBarrageView(et_senddanmu.getText().toString());
            }
        });

        findViewById(R.id.btn_stop).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                barrageview.stopBarrageView();
            }
        });
    }

    private void initView() {
        data = new ArrayList<>();
        for (int i = 0; i < 10000; i++) {
            String text = "弹幕内容";

            int random = (int) (Math.random() * 3);
            if(random == 0){
                text = "弹幕";
            }else if(random == 1){
                text = "超级长的弹幕内容测试弹幕内容测试";
            }else{
                text = "带颜色的";
            }
            int type = 1;
            if(i % 7 == 0){
                type = 2;
            }

            data.add(new Barrage(
                    text + i, "http://",type));
        }

        barrageview = (BarrageView) findViewById(R.id.barrageview);
        Log.d("TAG", data.size() + "");
        barrageview.setSentenceList(data);

    }
}
